/**
 * Created by ls.c on 2016/11/4.
 */
/**
 * get请求
 * @param  {String} options.url   api地址
 * @param  {String} options.query query参数
 * @return {Promise}               Promise
 *
 * 测试：http://localhost/gd
 * 正式：http://www.swidc.net
 */
pagination = (pageNumber,totalPage,eventFunction) => {

		var firstPage = 1;
		var lastPage = totalPage;
		if(totalPage>10){
			var avgPage = 10/2;
			firstPage = pageNumber - avgPage;
			lastPage =  pageNumber + avgPage - 1;
			if(firstPage<=0){
				lastPage = lastPage - firstPage +1;
				firstPage = 1;
			}else if(lastPage>totalPage){
				firstPage = firstPage - lastPage + totalPage;
				lastPage = totalPage;
			}
		}
		callBackFunction = function(i){
			eventFunction(i);
		}
		var pageStr = "";
		for(var i=firstPage;i<=lastPage;i++){
			var onClickStr = (i==pageNumber?"":("onclick='callBackFunction("+i+")'"));
			pageStr += "<li class=' "+(i==pageNumber?"active":"")+"'><a "+onClickStr+">"+i+"</a></li>";
		}
		$("#pageSpan").html(pageStr);
		if(1!=pageNumber){
			$("#page_first").removeClass('disabled').unbind().bind("click",function(){eventFunction(1);});
			$("#page_pre").removeClass('disabled').unbind().bind("click",function(){eventFunction(pageNumber-1);});
		}else{
			$("#page_first").addClass('disabled').unbind("click");
			$("#page_pre").addClass('disabled').unbind("click");
		}
		if(totalPage!=pageNumber){
			$("#page_last").removeClass('disabled').unbind().bind("click",function(){eventFunction(totalPage);});
			$("#page_next").removeClass('disabled').unbind().bind("click",function(){eventFunction(pageNumber+1);});
		}else{
			$("#page_last").addClass('disabled').unbind("click");
			$("#page_next").addClass('disabled').unbind("click");
		}

}


export default pagination
